<extend name="Index/index" />

<block name="include">
    <script src="__PUBLIC__/Admin/js/pintuer.js"></script>
   
</block>
<block name="main">
    <div class="panel admin-panel margin-top" id="add">
      <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 增加用户</strong></div>
      <div class="body-content">
        <form method="post" class="form-x" id="add-form" action="<{:U('Category/AddCategory')}>">    
            <div class="form-group">
                <div class="label">
                  <label>分类名：</label>
                </div>
                <div class="field">
                  <input type="text" class="input w50" value="" name="name" data-validate="required:请输入分类名" />
                  <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                  <label>父级分类</label>
                </div>
                <div class="field">
                    <select id="sort1" name="pid" class="input w50">
                        <option  value="">请选择分类</option>
                        <option  value="0">一级分类</option>
                        <foreach name="data" item="vo">
                            <option   value=<{$vo.id}>><{$vo.name}></option>
                        </foreach>   
                    </select>
                
                    <script>
                    $(function(){
                        $('#sort1').change(function(){
                            var pid =$('#sort1').val();
                            if(pid!=''&&pid!=0){
                                $.ajax({
                                    url:"<{:U('GetCategoryByPid')}>",
                                    data:"pid="+pid,
                                    type:'get',
                                    success:function(msg){
                                        var len= msg.length;
                                        if(len>0){
                                            $('#sort1').siblings('select').remove();
                                            $('#sort1').parent().append('<select id="sort2" class="input w50"> </select>');
                                            $('#sort2').append('<option  value="">请选择分类</option>');
                                            for (var i = 0; i < len; i++) {
                                                $('#sort2').append('<option  value='+msg[i]['id']+'>'+msg[i]['name']+'</option>');
                                            }
                                            $('#sort2').change(function(){
                                                    var val =$('#sort2').val();
                                                    if(val != ''){
                                                        $('#sort1').removeAttr('name');
                                                        $('#sort2').attr('name','pid');
                                                        $('#hidden').remove();
                                                    }else{
                                                        $('#sort2').removeAttr('name');
                                                        $('#sort1').attr('name','pid');
                                                    }
                                            });
                                        }else{
                                            $('#sort1').siblings('select').remove();
                                            // $('#hidden').remove();
                                        }
                                    }
                                });
                            }else{
                                $('#sort1').siblings('select').remove();
                            }                         
                        }); 

                    })
                    
                    </script>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>显示：</label>
                </div>
                <div class="field">
                    <div class="button-group radio">
                        <label class="button active">
                            <span class="icon icon-check"></span>             
                            <input name="display" value="1" type="radio" checked="checked">是             
                        </label> 
                        <label class="button">
                            <span class="icon icon-check"></span>             
                            <input name="display" value="0" type="radio" >否          
                        </label>             
        
                    </div>       
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                  <label></label>
                </div>
                <div class="field">
                  <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
                </div>
            </div>
        </form>
       
      </div>
    </div>
    
</block>